//
//  OEShopGoodTableViewCell.m
//  OneEightyNine
//
//  Created by Mac on 2019/3/7.
//  Copyright © 2019 stoneobs. All rights reserved.
//

#import "OEShopGoodTableViewCell.h"

@interface  OEShopGoodTableViewCell()
@property(nonatomic, strong) UIImageView                     *iconImageView;/**<  */
@property(nonatomic, strong) STLabel                     *nameLable;/**<  */
@property(nonatomic, strong) STLabel                     *moneyLable;/**<  */

@end
@implementation OEShopGoodTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self configSubView];
    }
    return self;
}
+ (CGFloat)cellHeight{
    return 90;
}
#pragma mark --subView
- (void)configSubView{
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 0, 80, 80)];
    imageView.image = [UIImage imageNamed:@""];
    [self addSubview:imageView];
    self.iconImageView = imageView;
    
    self.nameLable = [[STLabel alloc] initWithFrame:CGRectMake(self.iconImageView.right + 10, self.imageView.top, 200, 44)
                                                     text:@""
                                                textColor:FirstTextColor
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [self addSubview:self.nameLable];
    
    self.moneyLable = [[STLabel alloc] initWithFrame:CGRectMake(self.iconImageView.right + 10, self.imageView.top, 200, 25)
                                               text:@""
                                          textColor:FlatRed
                                               font:15
                                        isSizetoFit:NO
                                      textAlignment:NSTextAlignmentLeft]; 
    self.moneyLable.bottom = self.iconImageView.bottom;
    [self addSubview:self.moneyLable];
    
    CGFloat witdh = 22;
    self.addButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, witdh, witdh)
                                                     title:nil
                                                titleColor:nil
                                                 titleFont:0
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:@"50×50+"]];
    self.addButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    self.addButton.centerY = self.moneyLable.centerY;
    [self addSubview:self.addButton];
    
    self.numLable = [[STLabel alloc] initWithFrame:CGRectMake(self.imageView.right + 10, self.imageView.top, witdh, witdh)
                                               text:@""
                                          textColor:FirstTextColor
                                               font:15
                                        isSizetoFit:NO
                                      textAlignment:NSTextAlignmentCenter];
    [self addSubview:self.numLable];
    self.numLable.centerY = self.addButton.centerY;
    
    
    self.reduceButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, witdh, witdh)
                                               title:nil
                                          titleColor:nil
                                           titleFont:0
                                        cornerRadius:0
                                     backgroundColor:nil
                                     backgroundImage:nil
                                               image:[UIImage imageNamed:@"50×50-"]];
    self.reduceButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    self.reduceButton.centerY = self.moneyLable.centerY;
    [self addSubview:self.reduceButton];
}
- (void)layoutSubviews{
    self.addButton.right = self.width - 10;
    self.numLable.right = self.addButton.left;
    self.reduceButton.right = self.numLable.left;
}
- (void)setModel:(OEGoodModel *)model{
    _model = model;
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.goods_img]];
    self.nameLable.text = model.goods_name;
    NSString * price = model.shop_price;
    if (!price.length) {
        price = model.goods_price;
    }
    self.numLable.text = model.subtotal_number;
    self.moneyLable.text = [NSString stringWithFormat:@"%@/cup",price];
    self.moneyLable.attributedText = [self.moneyLable.text st_convertAttributeStringWithKeyWord:@"/cup" attributes:@{NSForegroundColorAttributeName:SecendTextColor,NSFontAttributeName:[UIFont systemFontOfSize:13]}];
    
}
@end
